// x进制转换为10进制
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int ret;
bool islet(char ch)
{
    return ch >= 'A' && ch <= 'Z';
}

bool isdig(char ch)
{
    return ch >= '0' && ch <= '9';
}

void x_to_n(string s, int x)
{
    int n = s.size();
    int j = 0;
    for(int i = n - 1;i >= 0;i--)
    {
        if (isdig(s[i]))
        {
            int t = s[i] - '0';
            ret += t * pow(x, n - 1 - i);
            j++;
        }
        if(islet(s[i]))
        {
            int t = s[i] - 'A' + 10;
            ret += t * pow(x, n - 1 - i);
        }
    }
    cout << ret << endl;
}

int main()
{
    int x;string s;
    cin >> x >> s;

    // x_to_n(s, x);
    int ret = stoi(s, NULL, x);
    cout << ret << endl;
    return 0;
}